package controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;

import dal.InitializeDAO;
import dal.JMLDatabase;
import dto.DatabaseIconDTO;

public class InitiliazeController {
	private JMLDatabase dao;

	/**
	 * Constructor
	 */
	public InitiliazeController() {
		super();
		this.dao = new JMLDatabase();

	}

	/**
	 * Initialize for system
	 * 
	 * @throws IOException
	 */
	public void initialize() throws IOException {
		InitializeDAO init = new InitializeDAO();
		init.initialize();
	}

	/**
	 * Get all database name
	 * 
	 * @return ArrayList<String>
	 */
	public ArrayList<DatabaseIconDTO> getAllDatabaseName() {
		ArrayList<String> dbs = dao.getAllDatabaseName();
		if (dbs == null) {
			return null;
		}
		Collections.sort(dbs);
		ArrayList<DatabaseIconDTO> result = new ArrayList<>();
		for (String name : dbs) {
			result.add(new DatabaseIconDTO(name));
		}
		return result;
	}
}
